import {
  getguifanDetail,
  getguifanList
} from '@/api/myapi/tixiwenjian';
import {
  findChouyangfanganOne,
  findChouyangfanganTwo,
  findChouyangfanganMany,
  findYangbenliangZima
} from "@/api/myapi/common.js"
export default {
  watch:{
    form:{
      handler(val){
        console.log(11111);
        console.log(val);
        if(val.examineShuiping &&val.piliang){
          this.findYangbenliangZima({pl:val.piliang,sp:val.examineShuiping},val);
        }
      },
      deep:true
    }
  },
  methods: {
   
    //  采购计划
    getdevelopmentplanList() {
      getguifanList({
          current: 1,
          size: 10000,
          processStatus: 7
        },
        'purchasemanageprocess'
      ).then(({
        data
      }) => {
        console.log(data);
        if (data && data.success) {
          this.developmentplanList = data.data.records;
        }
      });
    },

    //   原材料批号
    getPlanNumber(id, form) {
      let item = this.developmentplanList.find(item => item.id == id);
      form.cailiaoList = [];
      form.materialName = '';
      form.materialNumber = '';
      form.materialSku = '';
      getguifanDetail({
        id
      }, 'purchasemanageprocess').then(({
        data
      }) => {
        console.log(data);
        if (data.success) {
          form.cailiaoList = data.data.cailiaoList;
          this.$forceUpdate();
        }
      });
    },
    //  原材料
    materialChange(id, form) {
      let item = form.cailiaoList.find(item => item.id == id);
      console.log(item);
      form.materialName = item.cailiaoName;
      form.materialNumber = item.cailiaoNumber;
      form.materialSku = item.cailiaoSku;
    },
    //  检验方式
    examineWayChange(id, form) {
      console.log(id)
      let len = id == 0 ? 1 : id == 1 ? 2 : 5;
      form.yblList = [];
      for (let i = 0; i++, i <= len;) {
        form.yblList.push({
          buhegepinshu: "", //	不合格品数		false
          buhegeshu: "", //	不合格数
          hegepinshu: "", //	合格品数
          leijibuhegepinshu: "", //	累计不合格品数		false
          leijibuhegeshu: "", //	累计不合格数		false
          leijihegepinshu: "", //	累计合格品数
          isHege: "", //	批量合格/不合格；0-合格，1-不合格		false
          jieshoushu: "", //	接收数		false
          jushoushu: "", //	拒收数
        })
      }
      this.getSomeData(id, form);
    },
    //

    getSomeData(id, form) {
      let parmas = {
        examineLeibie: form.examineLeibie,
        aql: form.aql,
        zima: form.zima
      }
      console.log(parmas)
      if (form.examineLeibie && form.aql && form.zima) {
        if (id == 0) {
          this.findChouyangfanganOne(parmas, form)
        } else if (id == 1) {
          this.findChouyangfanganTwo(parmas, form)
        } else {
          this.findChouyangfanganMany(parmas, form)
        }
      }
    },
    //检验水平（IL）
    examineShuipingChange(id, form) {
      if (form.piliang) {
        this.findYangbenliangZima({
          pl: form.piliang,
          sp: id
        }, form)
      }
    },
    //  检验类别  0正常检验  1 加严检验 2 放宽检验
    examineLeibieChange(id, form) {
      console.log(form)
      if (form.examineWay) {
        this.getSomeData(form.examineWay, form);
      }
    },
    //  接受质量限制 +
    aqlChange(id, form) {
      console.log(id)
      if (form.examineWay) {
        this.getSomeData(form.examineWay, form);
      }
    }
  }
}
